package com.bolang.onlycode.demo;

import java.lang.reflect.Array;

public class BinarySearch {
    public static int binarySearch(int[] binaryArray,int target){
        int left=0;
        int right=binaryArray.length-1;
        while (left<=right){
            int mid= (left+right)/2;
            int present= binaryArray[mid];
            if(target>present){
                left=mid+1;
            }else if(target<present) {
                right=mid-1;
            }else {
                return mid;
            }
        }
        // 没找到结果返回-1
         return  -1;
    }

    public static void main(String[] args) {
        int[] a=new int[]{2,6,8,15,33,55,66,69,81};
        System.out.println(binarySearch(a, 70));
    }

}
